import { store } from "@/store";
import CommonAPI from "@/api/common";
import { TOKEN_KEY } from "@/enums/CacheEnum";

export const useCommonStore = defineStore("common", () => {
  const common = ref<any>({
    uploadUrl: `${import.meta.env.VITE_APP_BASE_API}/inter-api/smcc/v1/file/upload`,
    headers: {
      'X-clientType': 'web',
      Authorization: localStorage.getItem(TOKEN_KEY),
    },
    data: {
      type: 'image',
    }
  });

  function getDeviceInfoPage(params: any) {
    return CommonAPI.queryDeviceInfoPage(params)
  }

  function addDevice(data: any) {
    return CommonAPI.addDevice(data)
  }

  function editDevice(data: any) {
    return CommonAPI.editDevice(data)
  }

  function queryFreightRoadTemplatePage(data: any) {
    return CommonAPI.queryFreightRoadTemplatePage(data)
  }

  function addFreightRoadTemplate(data: any) {
    return CommonAPI.addFreightRoadTemplate(data)
  }

  function getFreightRoadTemplateDetail(params: any) {
    return CommonAPI.getFreightRoadTemplateDetail(params)
  }

  function delFreightRoadTemplate(params: any) {
    return CommonAPI.delFreightRoadTemplate(params)
  }

  function saveDistributorInfo(data: any) {
    return CommonAPI.saveDistributorInfo(data)
  }

  function queryDistributorInfoPage(data: any) {
    return CommonAPI.queryDistributorInfoPage(data)
  }

  function deleteDistributorInfo(params: any) {
    return CommonAPI.deleteDistributorInfo(params)
  }

  function queryDeviceGoodsOperateRecordPage(data: any) {
    return CommonAPI.queryDeviceGoodsOperateRecordPage(data)
  }

  function queryGoodsPage(data: any) {
    return CommonAPI.queryGoodsPage(data)
  }

  function queryGoodsCategoryPage(data: any) {
    return CommonAPI.queryGoodsCategoryPage(data)
  }

  function addGoodsCategory(data: any) {
    return CommonAPI.addGoodsCategory(data)
  }

  function updateGoodsCategory(data: any) {
    return CommonAPI.updateGoodsCategory(data)
  }

  function delGoodsCategory(params: any) {
    return CommonAPI.delGoodsCategory(params)
  }

  function getGoodsDetail(params: any) {
    return CommonAPI.getGoodsDetail(params)
  }

  function addGoods(data: any) {
    return CommonAPI.addGoods(data)
  }

  function updateGoods(data: any) {
    return CommonAPI.updateGoods(data)
  }

  function delGoods(params: any) {
    return CommonAPI.delGoods(params)
  }

  function getDeviceVersionConfigList(data: any) {
    return CommonAPI.getDeviceVersionConfigList(data)
  }

  function addDeviceVersionConfig(data: any) {
    return CommonAPI.addDeviceVersionConfig(data)
  }

  function enableDeviceVersionConfig(params: any) {
    return CommonAPI.enableDeviceVersionConfig(params)
  }

  function updateDeviceVersionConfig(data: any) {
    return CommonAPI.updateDeviceVersionConfig(data)
  }

  function getGlobalConfig() {
    return CommonAPI.getGlobalConfig()
  }

  function saveOrUpdateGlobalConfig(data: any) {
    return CommonAPI.saveOrUpdateGlobalConfig(data)
  }

  function getDeviceInfoDetailByCode(params: any) {
    return CommonAPI.getDeviceInfoDetailByCode(params)
  }

  function operateDeviceRoadUnitGoods(data: any) {
    return CommonAPI.operateDeviceRoadUnitGoods(data)
  }

  function queryTradeOrderPage(params: any) {
    return CommonAPI.queryTradeOrderPage(params)
  }

  function bindDeviceEmployeeRel(data: any) {
    return CommonAPI.bindDeviceEmployeeRel(data)
  }

  function quickFullRoadUnitGoods(data: any) {
    return CommonAPI.quickFullRoadUnitGoods(data)
  }

  function quickUpShelfRoadUnitGoods(data: any) {
    return CommonAPI.quickUpShelfRoadUnitGoods(data)
  }

  function tradeOrderPage(params: any) {
    return CommonAPI.tradeOrderPage(params)
  }

  return {
    common,
    getDeviceInfoPage,
    addDevice,
    editDevice,
    queryFreightRoadTemplatePage,
    addFreightRoadTemplate,
    delFreightRoadTemplate,
    saveDistributorInfo,
    queryDistributorInfoPage,
    deleteDistributorInfo,
    getFreightRoadTemplateDetail,
    queryDeviceGoodsOperateRecordPage,
    queryGoodsPage,
    queryGoodsCategoryPage,
    addGoodsCategory,
    updateGoodsCategory,
    delGoodsCategory,
    getGoodsDetail,
    addGoods,
    updateGoods,
    delGoods,
    getDeviceVersionConfigList,
    addDeviceVersionConfig,
    enableDeviceVersionConfig,
    updateDeviceVersionConfig,
    getGlobalConfig,
    saveOrUpdateGlobalConfig,
    getDeviceInfoDetailByCode,
    operateDeviceRoadUnitGoods,
    queryTradeOrderPage,
    bindDeviceEmployeeRel,
    quickFullRoadUnitGoods,
    quickUpShelfRoadUnitGoods,
    tradeOrderPage,
  };
});

/**
 * 用于在组件外部（如在Pinia Store 中）使用 Pinia 提供的 store 实例。
 * 官方文档解释了如何在组件外部使用 Pinia Store：
 * https://pinia.vuejs.org/core-concepts/outside-component-usage.html#using-a-store-outside-of-a-component
 */
export function useCommonStoreHook() {
  return useCommonStore(store);
}